const ocentCrawler = require('./services/ocentCrawler');
const { startOcentCrawlerSchedule } = require('./scheduleOcentCrawler');

async function runOnce() {
    try {
        // First login
        const loginSuccess = await ocentCrawler.login();
        if (!loginSuccess) {
            console.error('Login failed, program exiting');
            return;
        }

        // This can be replaced with the actual product ID
        const productId = 790;
        
        // Get product information
        const productInfo = await ocentCrawler.getProductInfo(productId);
        if (productInfo) {
            console.log('Successfully retrieved product information');
        }
    } catch (error) {
        console.error('Program execution error:', error);
    }
}

// Main function
async function main() {
    // Check command line arguments
    const args = process.argv.slice(2);
    
    if (args.includes('--schedule') || args.includes('-s')) {
        // Start scheduled task
        console.log('Starting scheduled task mode...');
        startOcentCrawlerSchedule();
    } else {
        // Default to run once
        console.log('Single run mode...');
        await runOnce();
    }
}

// Run main program
main();